//
//  UIViewController+ChooseInfoViewController.m
//  Utils
//
//  Created by enghou on 2018/6/7.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "UIViewController+ChooseInfoViewController.h"
#import "NetWorkerManager.h"
@implementation UIViewController (ChooseInfoViewController)


-(void)commonAlertWithContent:(NSString *)content choosenBlock:(void(^)(PropertyDictItemModel *))choosen getList:(void(^)(NSArray *))getList{
    [self beginLoading];
    [[NetWorkerManager sharedInstance]getPropertyDictWithDomainName:content successBlock:^(BaseModel *model) {
        [self endLoading];
        if (model.success) {
            getList(model.list);
            [self alertWithArray:model.list choosenBock:choosen];
        }else{
            [self alertSome:model.msg];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
}

-(void)alertWithArray:(NSArray <PropertyDictItemModel *>*)array choosenBock:(void(^)(PropertyDictItemModel *))choosen{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (PropertyDictItemModel *model in array) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:model.displayName style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            choosen(model);
        }];
        [alert addAction:action];
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}


@end
